﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Data;
using System.Data.SqlClient;
public partial class Good2 : System.Web.UI.Page
{
    protected void Page_Load(object sender, EventArgs e)
    {
        if (!IsPostBack)
        {
            Binddate();


        }
    }
   /* protected void btnUpdate_Click(object sender, EventArgs e)
    {
        users us = new users();
        us.id = txtUpdate.Text.Trim();
        us.name = txtUpdate.Text.Trim();
        GVmerch1.DataSource = us.GetOneUsers1(us);
        GVmerch1.DataBind();
        GVmerch1.Visible = true;
    }*/
    protected void GVmerch1_RowUpdating(object sender, GridViewUpdateEventArgs e)
    {

        string id = GVmerch1.DataKeys[e.RowIndex].Value.ToString().Trim();
        string name = ((TextBox)(GVmerch1.Rows[e.RowIndex].Cells[1].Controls[0])).Text.Trim();
        string price = ((TextBox)(GVmerch1.Rows[e.RowIndex].Cells[2].Controls[0])).Text.Trim();
        string descn = ((TextBox)(GVmerch1.Rows[e.RowIndex].Cells[3].Controls[0])).Text.Trim();
        string num = ((TextBox)(GVmerch1.Rows[e.RowIndex].Cells[4].Controls[0])).Text.Trim();
        string proid = ((TextBox)(GVmerch1.Rows[e.RowIndex].Cells[5].Controls[0])).Text.Trim();
        string prodate = ((TextBox)(GVmerch1.Rows[e.RowIndex].Cells[6].Controls[0])).Text.Trim();
        string todate = ((TextBox)(GVmerch1.Rows[e.RowIndex].Cells[7].Controls[0])).Text.Trim();
        users tmp = new users();
        tmp.id = id;
        tmp.name = name;
        tmp.price = price;
        tmp.descn = descn;
        tmp.num = num;
        tmp.proid = proid;
        tmp.prodate = prodate;
        tmp.todate = todate;
        tmp.Updateoneuser(tmp);
    }
    protected void GVmerch1_RowEditing(object sender, GridViewEditEventArgs e)
    {
   
        GVmerch1.EditIndex = e.NewEditIndex;
        Binddate();
   
    }
    protected void Binddate()
    {
        users us = new users();
        GVmerch1.DataSource = us.GetAllUsers1(us);
        GVmerch1.DataBind();
    }
    protected void GVmerch1_RowCancelingEdit(object sender, GridViewCancelEditEventArgs e)
    {
        GVmerch1.EditIndex = -1;
        Binddate();
    }
    protected void GVmerch1_RowDeleting(object sender, GridViewDeleteEventArgs e)
    {
        string id = GVmerch1.DataKeys[e.RowIndex].Value.ToString().Trim();
        users us = new users();
        us.id = id;
        us.delete(us);
        Binddate();
    }
    protected void GVmerch1_RowDataBound(object sender, GridViewRowEventArgs e)
    {
        if (e.Row.RowType == DataControlRowType.DataRow)
        {
            try
            {
                LinkButton lnkbtnDelete = (LinkButton)e.Row.Cells[9].Controls[0];
                lnkbtnDelete.OnClientClick = "return confirm('您真的要删除商品" + e.Row.Cells[1].Text + "的记录吗？');";
            }
            catch
            {

            }
        }
    }
}